function sumAll(arr) {
    const begin = Math.min(...arr);
    const end = Math.max(...arr);
    let result = 0;
    for (let i = begin, len = end; i <= len; i++) {
        result += i;
    }
    return result;
}

sumAll([1, 4]);
